package com.packet.controller;

import com.packet.service.ManagerApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author L
 */
@Controller
public class ManagerApprovalController {

    @Autowired
    ManagerApprovalService managerApprovalService;

    @GetMapping("/agree/{bid}")
    public String AgreeApplication(@PathVariable("bid") Integer bId){
        managerApprovalService.agreeApplication(bId);
        return "redirect:/maa";
    }

    @GetMapping("/refuse/{bid}")
    public String Refuse(@PathVariable("bid") Integer bId, Model model){
        model.addAttribute("bId",bId);
        return "maa/refuseReason";
    }

    @PostMapping("/refuseReason/{bid}")
    public String RefuseReasonApplication(@PathVariable("bid") Integer bId, @RequestParam("content") String detail){
        managerApprovalService.refuseApplication(bId);
        managerApprovalService.refuseReason(bId,detail);
        return "redirect:/maa";
    }

    @GetMapping("/reimburseAgree/{bid}")
    public String AgreeReimburse(@PathVariable("bid") Integer bId){
        managerApprovalService.agreeApplication(bId);
        return "redirect:/mar";
    }

    @GetMapping("/reimburseRefuse/{bid}")
    public String RefuseReimburse(@PathVariable("bid") Integer bId, Model model){
        model.addAttribute("bId",bId);
        return "maa/reimburseRefuseReason";
    }

    @PostMapping("/reimburseRefuseReason/{bid}")
    public String RefuseReasonReimburse(@PathVariable("bid") Integer bId, @RequestParam("content") String detail){
        managerApprovalService.refuseApplication(bId);
        managerApprovalService.refuseReason(bId,detail);
        return "redirect:/mar";
    }
}
